#include <sys/time.h>
#include <string>
#include <iostream>

using namespace std;

#ifndef _NDEBUG
    #define PERF(name) Perf perf_##name(#name)
#else
    #define PERF(name) 
#endif

class Perf {
public:
    Perf(const std::string& name)
    {
        m_name = name;
        gettimeofday(&m_start, NULL);
    }

    ~Perf() {
        gettimeofday(&m_end, NULL);
        double t = (m_end.tv_sec - m_start.tv_sec) * 1000.0 + (m_end.tv_usec - m_start.tv_usec) / 1000.0;
        cout << "block: " << m_name.c_str() << ", time elapse: " << t << "ms" << endl;
    }

private:
    struct timeval m_start;
    struct timeval m_end;
    std::string m_name;
}; // class Perf